package com.ddstation.exchange.controller;

import com.baidu.aip.util.Base64Util;
import com.ddstation.clinic_info.model.ClinicInfoModel;
import com.ddstation.clinic_info.service.ClinicInfoService;
import com.ddstation.common.model.ImageModel;
import com.ddstation.common.service.DataDictionaryService;
import com.ddstation.common.util.AliCloudOssUtil;
import com.ddstation.crm.institution.entity.DtHealthManageInstitutionEntity;
import com.ddstation.crm.login.bean.SessionLoginData;
import com.ddstation.doctor.entity.DdDoctorEntity;
import com.ddstation.doctor_verify.service.DoctorVerifyService;
import com.ddstation.exchange.service.out.DataFromInvsWebService;
import com.ddstation.master.entity.MaDataDictionaryEntity;
import com.ddstation.sewage.service.SewageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ExchangeHisDataController {

	/**
	 * 保存his数据接口
	 * 
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping(value="exchange_his_data.do/save", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> savaExchangeHisData(
			@RequestParam (required=true)String tableName,
			@RequestBody (required=true)List<Map<String,Object>> dataList,
			HttpSession session)  {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			Map<String, List<Object>> serviceResultMap = dataFromInvsWebService.saveAllTypesList(tableName, dataList);
			//处理service返回数据
			resultMap.put("completeIds",serviceResultMap.get("completeIds"));//完成ID集合
			resultMap.put("errorIds",serviceResultMap.get("errorIds"));//错误ID集合
			resultMap.put("errcode","0");//请求成功
		}catch (Exception e){
			resultMap.put("errcode","-1");
			resultMap.put("msg","接口请求异常！" + e.getMessage());
		}
		return resultMap;
	}

	/**
	 * 更新his数据接口
	 *
	 * @return
	 * @throws ParseException
	 */
	@RequestMapping(value="exchange_his_data.do/update", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> updateExchangeHisData(
			@RequestParam (required=true)String tableName,
			@RequestBody (required=true)List<Map<String,Object>> dataList,
			HttpSession session)  {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			Map<String, List<Object>> serviceResultMap = dataFromInvsWebService.updateAllTypesList(tableName, dataList);
			//处理service返回数据
			resultMap.put("completeIds",serviceResultMap.get("completeIds"));//完成ID集合
			resultMap.put("errorIds",serviceResultMap.get("errorIds"));//错误ID集合
			resultMap.put("errcode","0");//请求成功
		}catch (Exception e){
			resultMap.put("errcode","-1");
			resultMap.put("msg","接口请求异常！" + e.getMessage());
		}
		return resultMap;
	}

	/**
	 * 获取内网更新数据
	 *
	 * @return
	 * @throws ParseException
	 */
	@RequestMapping(value="exchange_his_data.do/getUpdateDate", method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> getUpdateExchangeHisData(
			@RequestParam (required=true)String tableName,
			@RequestBody (required=true)List<Map<String,Object>> dataList,
			HttpSession session)  {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			List<Map<String, Object>> updateList = dataFromInvsWebService.getUpdateList(tableName);
			//处理service返回数据
			resultMap.put("updateList",updateList);//更新数据集合
			resultMap.put("errcode","0");//请求成功
		}catch (Exception e){
			resultMap.put("errcode","-1");
			resultMap.put("msg","接口请求异常！" + e.getMessage());
		}
		return resultMap;
	}


	@Inject private DataFromInvsWebService dataFromInvsWebService;

}
